package com.guanyong.webapi.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


/**
 * Created by Administrator on 2017/6/28 0028.
 */
@Service
public class VoucherUtil {



    @Value("${ali.video.accessKeyId}")
    String accessKeyId ;
    @Value("${ali.video.accessKeySecret}")
    String accessKeySecret ;




    public String getVideoPlayAuth(String objectId) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(objectId);
        GetVideoPlayAuthResponse response = null;
        String playAuth = null;
        try {
            response = client.getAcsResponse(request);
            playAuth = response.getPlayAuth();
        } catch (ServerException e) {
            throw new RuntimeException("GetVideoPlayAuthRequest Server failed");

        } catch (ClientException e) {
            throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
        }

        return playAuth;
    }
}
